const path = require('path')
function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  lintOnSave: true,
  chainWebpack: config => {
    // 修复热更新
    config.resolve.symlinks(true)

    // 设置别名
    config.resolve.alias
      .set('@', resolve('src'))
      .set('@api', resolve('src/api'))
      .set('@assets', resolve('src/assets'))
      .set('@directive', resolve('src/directive'))
      .set('@filters', resolve('src/filters'))
      .set('@plugins', resolve('src/plugins'))
      .set('@router', resolve('src/router'))
      .set('@store', resolve('src/store'))
      .set('@utils', resolve('src/utils'))
      .set('@view', resolve('src/view'))
      .set('@layout', resolve('src/layout'))

    // 如果使用多页面打包，使用vue inspect --plugins查看html是否在结果数组中
    config.plugin('html').tap(args => {
      // 修复 Lazy loading routes Error
      args[0].chunksSortMode = 'none'
      return args
    })
  },

  devServer: {
    proxy: {
      // // xxx/api/login => http://203.195.134.62:543/login
      [process.env.VUE_APP_BASE_URL]: {
        target: 'http://203.195.134.62:8888/api/private/v1/',
        // target: 'http://127.0.0.1:8888/api/private/v1/',
        // target: 'http://127.0.0.1:8787',
        // target: 'http://127.0.0.1:6633',
        changeOrigin: true,
        pathRewrite: {
          ['^' + process.env.VUE_APP_BASE_URL]: '' // 路径重写
        }
      }
    }
  }
}
